home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / stevie / bsd.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  143 lines

  1. /*
  2.  * System-dependent routines for BSD 4.3 UNIX 
  3.  */
  4.  
  5. #include "stevie.h"
  6. #include <sgtty.h>
  7.  
  8. #ifdef OLD_IO
  9. #define BSIZE   2048
  10. static char     outbuf[BSIZE];
  11. static int      bpos = 0;
  12.  
  13. void
  14. flushbuf()
  15. {
  16.     if (bpos != 0)
  17.     fwrite(outbuf, sizeof(*outbuf), bpos, stdout);
  18.     fflush(stdout);
  19.     bpos = 0;
  20. }
  21.  
  22. void
  23. outchar(c)
  24.     char            c;
  25. {
  26.     outbuf[bpos++] = c;
  27.     if (bpos >= BSIZE)
  28.     flushbuf();
  29. }
  30.  
  31. void
  32. outstr(s)
  33.     char           *s;
  34. {
  35.     while (*s) {
  36.     outbuf[bpos++] = *s++;
  37.     if (bpos >= BSIZE)
  38.         flushbuf();
  39.     }
  40. }
  41. #endif
  42.  
  43. /*
  44.  * inchar() - get a character from the keyboard 
  45.  */
  46. int
  47. inchar()
  48. {
  49.     int             c;
  50.  
  51.     flushbuf();            /* flush any pending output */
  52.  
  53.     c = getchar();
  54.  
  55.     return c;
  56. }
  57.  
  58. void
  59. beep()
  60. {
  61.     if (RedrawingDisabled)
  62.     return;
  63.  
  64.     outchar('\007');
  65. }
  66.  
  67. void
  68. delay()
  69. {
  70.     sleep(1);
  71. }
  72.  
  73. static struct sgttyb ostate;
  74.  
  75. void
  76. windinit()
  77. {
  78.     char           *getenv();
  79.     struct sgttyb   nstate;
  80. #ifdef CHECK_TERM
  81.     char           *term;
  82.  
  83.     term = getenv("TERM");
  84.     if (!term) {
  85.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  86.     exit(1);
  87.     }
  88.     if ((strncmp(term, "vt", 2) != 0) && (strncmp(term, "kd", 2) != 0)) {
  89.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  90.     exit(1);
  91.     }
  92. #endif
  93.  
  94.     Columns = 80;
  95.     P(P_LI) = Rows = 24;
  96.  
  97.     /*
  98.      * Go into cbreak mode 
  99.      */
  100.     ioctl(1, (long) TIOCGETP, (char *) &ostate);
  101.     nstate = ostate;
  102.     nstate.sg_flags = nstate.sg_flags & ~(ECHO | CRMOD) | CBREAK;
  103.     ioctl(1, (long) TIOCSETP, (char *) &nstate);
  104. }
  105.  
  106. void
  107. windexit(r)
  108.     int             r;
  109. {
  110.     flushbuf();
  111.  
  112.     ioctl(0, (long) TIOCSETP, (char *) &ostate);
  113.  
  114.     exit(r);
  115. }
  116.  
  117. void
  118. windgoto(r, c)
  119.     int             c;
  120.     int             r;
  121. {
  122.     r++;
  123.     c++;
  124.  
  125.     outstr("\033[");
  126.     if (r >= 10)
  127.     outchar((char) (r / 10 + '0'));
  128.     outchar((char) (r % 10 + '0'));
  129.     outchar(';');
  130.     if (c >= 10)
  131.     outchar((char) (c / 10 + '0'));
  132.     outchar((char) (c % 10 + '0'));
  133.     outchar('H');
  134. }
  135.  
  136. FILE           *
  137. fopenb(fname, mode)
  138.     char           *fname;
  139.     char           *mode;
  140. {
  141.     return fopen(fname, mode);
  142. }
  143.